package com.shxzz.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.shxzz.shortlink.project.common.convention.result.Result;
import com.shxzz.shortlink.project.common.convention.result.Results;
import com.shxzz.shortlink.project.dto.req.GroupLinkAccessRecordReqDTO;
import com.shxzz.shortlink.project.dto.req.GroupLinkStatusReqDTO;
import com.shxzz.shortlink.project.dto.req.LinkAccessRecordReqDTO;
import com.shxzz.shortlink.project.dto.req.LinkStatusReqDTO;
import com.shxzz.shortlink.project.dto.resp.GroupLinkAccessRecordRespDTO;
import com.shxzz.shortlink.project.dto.resp.GroupLinkStatusRespDTO;
import com.shxzz.shortlink.project.dto.resp.LinkAccessRecordRespDTO;
import com.shxzz.shortlink.project.dto.resp.LinkStatusRespDTO;
import com.shxzz.shortlink.project.service.LinkStatusService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shxzz
 * @create 2023-12-27-22:19
 * @description 短链接访问信息控制层
 */
@RestController
@RequiredArgsConstructor
public class LinkStatusController {

    private final LinkStatusService linkStatusService;

    /**
     * 访问单个短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/v1/stats")
    public Result<LinkStatusRespDTO> shortLinkStats(LinkStatusReqDTO requestParam) {
        return Results.success(linkStatusService.oneLinkStatus(requestParam));
    }

    /**
     * 访问单个短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/v1/stats/access-record")
    public Result<IPage<LinkAccessRecordRespDTO>> shortLinkStatsAccessRecord(LinkAccessRecordReqDTO requestParam) {
        return Results.success(linkStatusService.selectLinkAccessRecord(requestParam));
    }

    /**
     * 访问分组短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/v1/stats/group")
    public Result<GroupLinkStatusRespDTO> groupShortLinkStats(GroupLinkStatusReqDTO requestParam) {
        return Results.success(linkStatusService.groupLinkStatus(requestParam));
    }

    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/short-link/v1/stats/access-record/group")
    public Result<IPage<GroupLinkAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(GroupLinkAccessRecordReqDTO requestParam) {
        return Results.success(linkStatusService.selectGroupLinkAccessRecord(requestParam));
    }
}
